function Teacher() {
  this.eat = "馒头";
  this.play = "唱歌";
  this.obj = {
    a: 1,
    b: 2,
  };
}
Teacher.prototype.say = function () {
  console.log(`吃${this.eat},然后去${this.play}`);
};

function Student1() {}

// 原型链继承，new Teacher的过程this唯一的，导致student11,student12中的obj是同一个引用，会相互干扰
Student1.prototype = new Teacher();
// 继承之后
const student11 = new Student1();
const student12 = new Student1();

console.log(student11, student12);
student11.obj.a = 100000;
console.log(student11, student12);

// 我们使用构造函数继承的方法，能产生多个this，避免重复引用
// 但是这样会导致Teacher执行两次：new Teacher、  Teacher.call()
function Student2() {
  Teacher.call(this);
}
Student2.prototype = new Teacher();

const student13 = new Student2();
const student14 = new Student2();

console.log(student13, student14);
student13.obj.a = 100000;
console.log(student13, student14);


// 然后用Object.create替代 new Teacher

function Student3() {
    Teacher.call(this);
}
Student3.prototype = Object.create(Teacher.prototype);
Student3.prototype.constructor = Student3;

const student15 = new Student3();
const student16 = new Student3();

console.log(student15, student16);
student15.obj.a = 100000;
console.log(student15, student16);
